package com.goldze.mvvmhabit.ui.tab_bar.fragment;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.goldze.mvvmhabit.R;
import com.goldze.mvvmhabit.databinding.FragmentTabBar4Binding;
import com.goldze.mvvmhabit.ui.feed.FeedActivity;
import com.goldze.mvvmhabit.ui.login.LoginActivity;
import com.goldze.mvvmhabit.ui.register.RegisterActivity;
import com.goldze.mvvmhabit.utils.GlideUtil;
import com.goldze.mvvmhabit.utils.SpUtils;

/**
 * Created by goldze on 2018/7/18.
 * SpUtils.put("module_token",loginBean.getResult().getToken());
 * SpUtils.put("module_username", loginBean.getResult().getUser().getUsername());
 * SpUtils.put("module_name", loginBean.getResult().getUser().getName());
 * SpUtils.put("module_tel", loginBean.getResult().getUser().getMobile());
 * SpUtils.put("module_schoolname", loginBean.getResult().getUser().getSchool());
 * SpUtils.put("module_age", loginBean.getResult().getUser().getAge());
 * SpUtils.put("module_student_number",loginBean.getResult().getUser().getNumber());
 */

public class TabBar4Fragment extends Fragment {

    FragmentTabBar4Binding binding;
    String uname, tel, schoolName, age, number,headUrl;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.fragment_tab_bar_4, container, false);
        binding.setFragment(this);
        initData();
        return binding.getRoot();
    }

    private void initData() {
        uname = (String) SpUtils.get("module_name", "");
        tel = (String) SpUtils.get("module_tel", "");
        schoolName = (String) SpUtils.get("module_schoolname", "");
        age = (String) SpUtils.get("module_age", "");
        number = (String) SpUtils.get("module_student_number", "");
        headUrl = (String)SpUtils.get("module_photo","");
        if (!TextUtils.isEmpty(headUrl)) {
            GlideUtil.newCacheInstance(headUrl,binding.ivModuleHead);
        }


        binding.tvModuleName.setText(uname);
        binding.tvModuleTel.setText(tel);
        binding.tvModuleSchool.setText(schoolName);
        binding.tvModuleAge.setText("年龄" + age);
        binding.tvModuleNumber.setText(number);

        //反馈点击事件
        binding.tvModuleFeed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), FeedActivity.class));
            }
        });

        //退出点击事件
        binding.tvModuleOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SpUtils.clear(getActivity());
                startActivity(new Intent(getActivity(), LoginActivity.class));
            }
        });

        //修改个人信息
        binding.tvModuleChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SpUtils.put("module_register","update");
                startActivity(new Intent(getActivity(), RegisterActivity.class));
            }
        });
    }

}
